/**
 * 
 */
package table;

import java.awt.Component;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import database.DataType;
/**
 * @author Ken
 *
 */
public class ComboboxRenderer extends JComboBox implements TableCellRenderer{
	public ComboboxRenderer() {
		super();
		DataType data = DataType.GetInstance();
		List<String> types = data.get_dataType();
		for (int i = 0; i < types.size(); i++) {
			addItem(types.get(i));
		}
	}	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if(isSelected){
            setForeground(table.getSelectionForeground());
            super.setBackground(table.getSelectionBackground());
        }else{
            setForeground(table.getForeground());
            setBackground(table.getBackground());
        }
        boolean isInt = value.toString().equals("int");        
        setSelectedIndex(isInt ? 0 : 1);
        return this;
    }
}
